<template>
	<view class="mian">		
		<!-- #ifdef MP-WEIXIN -->
		<navbar  title="积分兑换" :isGoBack="true" :isNotice="true" :bgColor="bgColor" :btnColors='btnColor' :visible="true" ></navbar>
		<!-- #endif -->	
		<view class="main-cur pb-20">			
			<view class="pt-10">
				<view class="address-title border-b">
					收货地址
				</view>
			    <view  class="flex justify-center align-center confirm-address-add"  style=" background: #fff; height: 80rpx; line-height: 2.55555556;" @click="bindAddress" v-if="address==''">
			      <iconfont class="mr-10" icon="icon-plus" color="#2B91ED" size="40rpx" />
			      <text class="text-df" style="color:#2B91ED">添加收货地址</text>
			    </view>			   
			    <view isLink v-if="address !=''" class="flex " style="height: 110rpx;background-color: #fff;padding-left: 30rpx;" @click="routeToNext(2)">
					<view slot="icon" class="flex  justify-start confirm-address-icon">
						<u-icon  color="#2979ff" size="28" :name="api_url+'/static/upload/4a3840ad5ac741bd/2af6be447920c655.png'"></u-icon>
					</view>
					<view class="flex justify-between mt-15" style="width: 100%">
						<view  class="flex flex-direction  confirm-address-wrap ml-15">
							<view class="m-5">					  
								<text class="text-lg" style="color: #000000;">{{address.realname}}</text>
								<text  class="ml-10 text-lg">{{address.phone}}</text>
							</view>
							<view class="flex mt-5">
							   <view class="confirm-address-wrap-detail text-df text-gray">{{address.province}}{{address.city}}{{address.region}}{{address.address}}</view>
							</view>
					  </view>	     
				   </view>
			    </view>			   
			</view>						
		</view>	
		<view class="main-cur mt-20">
			<view class="address-title border-b">
				商品清单
			</view>
			<view class="flex pl-35">
				<view slot='icon' class="flex align-center">
					<image class="grid-img" :src="goods_info.goods_image" bindtap="handleChangeGoods" 	mode="scaleToFill"></image>
			    </view>
				<view class=" flex flex-direction ml-10"  style="width: 100%;">
					<view class="flex" style="flex-direction:column;margin-top: 20rpx;">
						<view class='flex align-center cell ellipsis-l2 text-content goods_title' style="color: #4D4D4D;">{{goods_info.goods_title}}</view>						
					</view>
					<view class="flex justify-between" style="margin-top: 20rpx; color: #999999;">
						<view class='flex align-center cell ellipsis-l2 '>{{goods_info.goods_desc}}</view>	
						<view style="margin-right: 5rpx;">×1</view>
					</view>
					<view class="flex mt-20 align-center text-center">
						<view class='flex align-center cell  text-content' style="color: #000000 ;font-weight: bold;">积分 </view>
						<view class='flex  ml-10 cell  text-content' style="color: #FE6200;">{{goods_info.goods_points}}</view>
					</view>
				</view>
			</view>					
					
		</view>	
		
		<view class="flex mt-20 align-center justify-between align-center pl-20 pt-20 pb-20" style=" background: #fff; height: 80rpx;width: 100%; margin-bottom: 150rpx;">
			<view class="flex mt-15 justify-between" style="width: 100%;">
				<view class="address-title">订单备注</view>
				<input  v-model="remark" class="uni-input mr-30 text-right" focus placeholder="50字以内（选填）"  />	
			</view>			
		</view>			
		<view class="flex mb-30" style=""></view>		 		
		<!-- 地址信息 -->
		<biz-address  :show="showSelection" ref="goodsSpec" @chooseCancel="chooseCancel"  @chooseaddess='chooseaddess'></biz-address>	  
		<!-- 结算信息 -->
		<t-submit-bar :show="showPay" :maskClosable="showSelection"  :setting_money="goods_info.goods_points+''"   @confirm="wxconfirm"  :type="settle_type"></t-submit-bar>	
	
	</view>
</template>

<script>
	import address from "@/components/address/index.vue";
	import submit from "@/components/submit-bar/index.vue";
	import picker from "@/components/date-picker/index.vue";

	export default {
		components: {
		   "biz-address": address,
		   "t-submit-bar": submit,
		   "date-picker": picker,
		},
		data () {
			return {	
				...getApp().globalData.config,
				value:'',
				pay_types:1,			
				showSelection:false,
				showPay:true,
				settle_type:8,				
				remark:"",			
				goodsId:'',
				addressId:'',
				address:'',
				goods_info:''
				
			}
		},
		onLoad(options) {
			if(options.addressId) this.addressId=options.addressId
			this.goodsId=options.goodsId
				  
		},		      
		onShow(){
		     this.goodsInfo()
		},
		methods:{
			...getApp().globalData.function,
			//获取商品信息
			goodsInfo(){
				let that=this 
				let obj_data={
				   type:1,
				   token:uni.getStorageSync('userInfo').token,
				   goodsId:this.goodsId,
				   addressId:this.addressId,
				}  
				if(uni.getStorageSync('userInfo')){
					obj_data.token=uni.getStorageSync('userInfo').token
				}
				
			    this.$http.pointsInfo(obj_data).then(res =>{
				 if(res.resCode=="9999"){
					 that.addressId=res.data.address.id
					 that.address=res.data.address
				    that.goods_info=res.data.lists
				 }else{
				   uni.showToast({title:res.resMessage,icon:"none"})
				 }
			 })
			},		
			
			
			
			
			//跳转地址
			bindAddress(){
				let qucik = JSON.parse(this.quick_info)
				uni.navigateTo({
					url:"/pages/pagesuser/address/add-edit/index?type=c&quick_info="+this.quick_info
				})
			},
			//确认地址
			chooseaddess(events){
				this.addressId=events.id				
				this.goodsInfo()
				this.showSelection=false
			},
			
			
			//选择收货地址
			routeToNext(type){	
				let that=this
				this.$http.AddressList({
					token:uni.getStorageSync('userInfo').token,
					login_type:'app',
					type,
					}).then(res=>{
					if(res.resCode=='9999'){
						this.showSelection=true
						that.$refs.goodsSpec.showSpecs(res.data)        
					}
				}) 			
			},
			chooseCancel(){
				this.showSelection=false
			},			
			//立即购买 quick
			wxconfirm(){     
			  let that = this
			  if(!this.addressId){
				  uni.showToast({title:'请添加收货地址~',icon:"none"})
				  return
			  }
			  
			   this.$http.DochangeGoods({
			  	 goodsId:this.goodsId,
				 remark:this.remark,
				 addressId:this.addressId,
			  	 token:uni.getStorageSync('userInfo').token,
			   }).then(res=>{
			  	   if(res.resCode=='9999'){
			  		   uni.showToast({title:'领取成功~',icon:'none'})
			  		   setTimeout(()=>{
			  		   		  that.$routers.router('/pages/pagesuser/points/exchange','navigateTo') 					  
			  		   },2000) 				 
			  	   }else that.$showToast(res.resMessage)
			   })
			},
		}
	}
</script>

<style>
	@import "./settlement.css";
</style>